<?php

/**
 * @author lebachvu
 * @copyright 2012
 */

class Login
{
    var $userName;
    var $passWord;
           
    public function set_session($name, $value)
    {        
        $_SESSION[$name] = $value; 
    }
    
    public function set_cookie($cName, $cValue, $cExpire)
    {
        setcookie($cName, $cValue, $cExpire);        
    }
    
    public function checkLogin($uname, $pwrod, $isSave)    
    {
        
        //echo $uname. $pwrod. $isSave ;
        //exit;
        
        $userNameDB = "admin";
        $passWordDB = md5("aa");
        $userTypeDB = '1';          //1: Admin, 2: Mod, 3: User, 4: banner
        $flag = 0;                  //0: Default; 1: Sai Username; 2: Sai Password; 3: Dung.  
        
        if($uname != '' || $pwrod != '')
        {
            if($uname == $userNameDB)
            {
                if (md5($pwrod) == $passWordDB)
                {
                    //save login user on server 
                    $this->set_session('uName', $uname);
                    $this->set_session('uType', $userTypeDB);
                    
                    // save login user on client
                    if($isSave == 'on')                             
                    {
                        $this->set_cookie('uName', $uname, time()+3600);
                        $this->set_cookie('uType', $userTypeDB, time()+3600);
                    }
                    
                    $flag = 3;
                } 
                else
                {
                    $flag = 2;
                    
                }                
            }
            else
            {
                $flag = 1;
            }
        }  
        return $flag;             
    }
    
    
    public function ResultLogin()
    {
        switch($this->returnLogin)
        {
            default:
                $viewLogin = "Username & Password is not found";
                break;
            case 1:
                $viewLogin = "Username is not exist";
                break;
            case 2:
                $viewLogin = "Password is not exist";
                break;
                
            case 3:
                $viewLogin = "Login success";
                break;
            
        }
        return $viewLogin;
    }
}

?>